#ifndef __PCF8574_H__
#define __PCF8574_H__
#include "my_include.h"

extern u8 PCF8574_Timer;

#define PCF8574_SCL        PBout(6) 
#define PCF8574_SDA        PBout(7)	
#define PCF8574_SDA_DataIN PBin(7)

#define PCF8574_SDA_IN              {GPIOB->CRL&=0X0FFFFFFF;GPIOB->CRL|=(u32)8<<28;}
#define PCF8574_SDA_OUT             {GPIOB->CRL&=0X0FFFFFFF;GPIOB->CRL|=(u32)3<<28;}  

#define PCF8574A_write  0x40
#define PCF8574A_read   0x41
#define PCF8574B_write  0x4E
#define PCF8574B_read   0x4F
#define PCF8574C_write  0x4C
#define PCF8574C_read   0x4D
#define PCF8574D_write  0x48
#define PCF8574D_read   0x49

#define ReadPCF8574A    PCF8574_Read(PCF8574A_read)
#define ReadPCF8574B    PCF8574_Read(PCF8574B_read)
#define ReadPCF8574C    PCF8574_Read(PCF8574C_read)
#define ReadPCF8574D    PCF8574_Read(PCF8574D_read)

//*****************新动环扩展引脚定义***********************//

#define LINKAGE_OUT(s)     ControlPin(PCF8574A_write,2,s);    //消防联动输出 p0-0
#define ALARM_OUT(s)       ControlPin(PCF8574A_write,1,s);    //告警灯输出   p0-1
#define POWER_12VOUT(s)    ControlPin(PCF8574A_write,2,s);    //12V 输出     p0-2
#define LIGHTING_OUT(s)    ControlPin(PCF8574A_write,1,s);    //照明灯输出   p0-3
#define RELAY_K7_OUT(s)    ControlPin(PCF8574A_write,2,s);    //K7继电器输出 p0-4 
#define RELAY_K5_OUT(s)    ControlPin(PCF8574A_write,2,s);    //K5继电器输出 p0-5 
#define RELAY_K4_OUT(s)    ControlPin(PCF8574A_write,2,s);    //K4继电器输出 p0-6 
#define RELAY_K2_OUT(s)    ControlPin(PCF8574A_write,2,s);    //K2继电器输出 p0-7 
#define RELAY_K1_OUT(s)    ControlPin(PCF8574A_write,2,s);    //K1继电器输出 p1-4 


#define ACCESSStatus        ((ReadPCF8574A&0x80)>>0)    //门禁传感器  p1-0
#define WATERStatus         ((ReadPCF8574A&0x08)>>1)    //防雷传感器  p1-1
#define INFRAEDStatus       ((ReadPCF8574A&0x10)>>2)    //红外传感器  p1-2
#define SMOKEStatus         ((ReadPCF8574A&0x04)>>3)    //烟雾传感器  p1-3



#define NoEquipment          0x01     //空载
#define EquipmentWork        0x02     //工作
#define EquipmentAberrancy   0x03     //异常
#define StandbyEquipment     0x04     //待机
#define NoPowerSupply        0x05     //无电源接入
#define PowerSupplyAberrancy 0x06     //电源异常

void Init_PCF8574(void);
u8 PCF8574_Read(u8 PCF8574TS);
u8 PCF8574_Write(u8 PCF8574TS,u8 data);
void ControlPin(u8 add,u8 pin,u8 onoff);
void Pcf8574_Control_Pin(u8 add,u8 pin,u8 onoff);
#endif
